import React from 'react';
import {Button,Form, Input, Icon, Card, message} from 'antd';
import axios from '../common/axios';

export default Form.create({
  username: '',
  password: ''
})(props=>{
  const {getFieldDecorator,validateFields}=props.form;

  const fnClick=ev=>{
    validateFields(async (err, values)=>{
      if(!err){
        try{
          await axios({
            url: '/team',
            method: 'post',
            data: values
          });

          message.success('团队成员添加成功');
        }catch(e){
          let {msg}=e.response.data;

          message.error(msg);
        }
      }
    });
  };

  return (
    <Card>
      <Form>
        <Form.Item>
          {getFieldDecorator('username', {})(
            <Input placeholder="请添加用户名" prefix={<Icon type="user" />} />
          )}
        </Form.Item>
        <Form.Item>
          {getFieldDecorator('password', {})(
            <Input type="password" placeholder="请输入密码" prefix={<Icon type="lock" />} />
          )}
        </Form.Item>
        <Form.Item>
          <Button type="primary" onClick={fnClick}>添加</Button>
        </Form.Item>
      </Form>
    </Card>
  );
});
